#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
using namespace std;
typedef long long ll;
const int N=1e5+10;
ll a[N];
ll s[N];
void solve() {
	ll sum=0;
	ll n;
	cin>>n;
	for(int i=1; i<=n; i++) {
		cin>>a[i];
		sum+=a[i];
	}
	if(sum%3!=0 || n<3) {
		cout<<0;
		return;
	}
	int num=sum/3;
	for(int i=1; i<=n; i++ ) {
		s[i]=s[i-1]+a[i];
	}
	ll idx=0;
	ll ans=0;
	for(int i=1; i<=n-1; i++) {
		if(s[i]==num ) {
			idx++;
		}  if(s[i]==num*2 ) {
		    if(num==0)
		    ans--;
			ans+=idx;
		}
	}
	cout<<ans;

}
int main() {

	solve();

	return 0;
}

